<!DOCTYPE html>
<html lang="zxx">
<head>
    <title>Fort - 活动细节</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta charset="utf-8">

    <!-- External CSS libraries -->
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="css/animate.min.css">
    <link rel="stylesheet" type="text/css" href="css/bootstrap-submenu.css">

    <link rel="stylesheet" type="text/css" href="css/bootstrap-select.min.css">
    <link rel="stylesheet" type="text/css" href="css/magnific-popup.css">
    <link rel="stylesheet" href="css/leaflet.css" type="text/css">
    <link rel="stylesheet" href="css/map.css" type="text/css">
    <link rel="stylesheet" type="text/css" href="fonts/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="fonts/flaticon/font/flaticon.css">
    <link rel="stylesheet" type="text/css" href="fonts/linearicons/style.css">
    <link rel="stylesheet" type="text/css" href="css/jquery.mCustomScrollbar.css">
    <link rel="stylesheet" type="text/css" href="css/dropzone.css">
    <link rel="stylesheet" type="text/css" href="css/slick.css">

    <!-- Custom stylesheet -->
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <link rel="stylesheet" type="text/css" id="style_sheet" href="css/skins/default.css">

    <!-- Favicon icon -->
    <link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon">


    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link rel="stylesheet" type="text/css" href="css/ie10-viewport-bug-workaround.css">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]>
    <script src="js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="js/html5shiv.min.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->
    <script src="js/jquery-2.2.0.min.js"></script>
    <script src="js/popper.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/bootstrap-submenu.js"></script>
    <script src="js/rangeslider.js"></script>
    <script src="js/jquery.mb.YTPlayer.js"></script>
    <script src="js/bootstrap-select.min.js"></script>
    <script src="js/jquery.easing.1.3.js"></script>
    <script src="js/jquery.scrollUp.js"></script>
    <script src="js/jquery.mCustomScrollbar.concat.min.js"></script>
    <script src="js/leaflet.js"></script>
    <script src="js/leaflet-providers.js"></script>
    <script src="js/leaflet.markercluster.js"></script>
    <script src="js/dropzone.js"></script>
    <script src="js/slick.min.js"></script>
    <script src="js/jquery.filterizr.js"></script>
    <script src="js/jquery.magnific-popup.min.js"></script>
    <script src="js/jquery.countdown.js"></script>
    <script src="js/maps.js"></script>
    <!--<script  src="js/app.js"></script>-->

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="js/ie10-viewport-bug-workaround.js"></script>
    <!-- Custom javascript -->
    <script src="js/ie10-viewport-bug-workaround.js"></script>
</head>
<body>


<!-- Main header start -->
<header class="main-header fixed-header-2">
    <div class="container">
        <nav class="navbar navbar-expand-lg navbar-light">
            <a class="navbar-brand company-logo" href="/index">
                <img src="img/logos/black-logo.png" alt="logo">
            </a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
                    aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav header-ml">
                    <li class="nav-item dropdown active">
                        <a class="nav-link " href="/activity" id="navbarDropdownMenuLink">
                            活动广场
                        </a>
                    </li>

                    <li class="nav-item dropdown active" id="myself">

                    </li>

                    <li class="nav-item dropdown active" id="admin_center">

                    </li>

                    <li class="nav-item dropdown megamenu-li">
                        <a class="nav-link " href="/about">关于我们</a>
                    </li>
                    <li class="nav-item dropdown megamenu-li">
                        <a class="nav-link " href="/contact">与管理员联系</a>
                    </li>
                </ul>
                <ul class="navbar-nav ml-auto" id="status">

                </ul>
            </div>
        </nav>
    </div>
</header>
<!-- Main header end -->

<!-- Sub banner start -->
<div class="sub-banner">

</div>
<!-- Sub Banner end -->
<!--<input type="text" id="id">-->
<!-- Blog body start -->
<div class="blog-body content-area-4">
    <div class="container">
        <div class="row" id="body">


        </div>
    </div>
</div>
<!-- Blog body end -->


<script>

    const token = localStorage.getItem("token");
    var id = window.location.search.split("=")[1];

    $(function f() {
        getLottery(id);
        //token存在
        if (token != null && token != '') {
            $.ajax({
                url: "http://localhost:5761/lottery-system-user/user/api/user/testToken",
                // url: "http://localhost:5710/user/api/user/testToken?token=" + token,
                type: "GET",
                beforeSend: function (XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader("token", token);
                },
                success: function (result) {
                    // console.log(result);
                    if (result.code == 999) {
                        alert(result.message);
                        localStorage.removeItem("token");
                        localStorage.removeItem("userNo");
                        document.getElementById("status").className = "navbar-nav ml-auto";
                        var content = "<li class='nav-item'><a class='nav-link' href='/login'>您好，请登录</a></li>" +
                            "<li class='nav-item'><a class='nav-link' href='/register' style='color:red'>免费注册</a></li>";
                        $("#status").append(content);
                        return;
                    }
                    if (result.code == 200) {
                        //正常
                        $("#myself").append("<a class='nav-link' href='/my-profile'>个人中心</a>");
                        var url = result.data.headImgUrl;
                        document.getElementById("status").className = "navbar-buttons ml-auto d-none d-xl-block d-lg-block";
                        var content = "<div><ul><li>" +
                            "<div class='dropdown btns'>" +
                            "<a class='dropdown-toggle' data-toggle='dropdown' id='username'></a>" +
                            "<div class='dropdown-menu'>" +
                            "<a class='dropdown-item' href='/forgot-password'>重置密码</a>" +
                            "<a class='dropdown-item' id='logout'>退出</a>" +
                            "</div></div></li></ul></div>";
                        $("#status").append(content);
                        document.getElementById("username").innerHTML = "<img src=" + url + " alt='avatar' >" + result.data.username;
                        //退出
                        $("#logout").click(function () {
                            localStorage.removeItem("token");
                            localStorage.removeItem("userNo");
                            window.location.href = "http://localhost/login";
                        });
                        //如果是商家身份，则添加菜单
                        if (result.data.userType == 1) {
                            $("#admin_center").append("<a class='nav-link ' href='/lottery_management' >管理中心</a>");
                        }
                        return;
                    } else {
                        //token过期或异常
                        document.getElementById("status").className = "navbar-nav ml-auto";
                        var content = "<li class='nav-item'><a class='nav-link' href='/login'>您好，请登录</a></li>" +
                            "<li class='nav-item'><a class='nav-link' href='/register' style='color:red'>免费注册</a></li>";
                        $("#status").append(content);
                        localStorage.removeItem("token");
                        localStorage.removeItem("userNo");
                        return;
                    }
                }
            });
        } else {
            //token不存在
            document.getElementById("status").className = "navbar-nav ml-auto";
            var content = "<li class='nav-item'><a class='nav-link' href='/login'>您好，请登录</a></li>" +
                "<li class='nav-item'><a class='nav-link' href='/register' style='color:red'>免费注册</a></li>";
            $("#status").append(content);
            return;
        }
    });


    function getLottery(id) {
        // console.log(id);
        var nums = getJoinNums(id);
        $.ajax({
            url: "http://localhost:5761/lottery-system-lottery/lottery/api/lottery/getLottery/" + id,
            type: "GET",
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("token", token);
            },
            success: function (result) {
                // console.log(result);
                if (result.code == 100) {
                    alert("此抽奖活动不存在");
                    return window.history.back();
                }
                $("#body").empty();

                var imagTd = $("<div class='col-lg-6' ></div>");

                var carouseTd = $("<div id='carouselExampleIndicators' class='carousel slide col-lg-12' data-ride='carousel'></div>");

                var olnumTd = $("<ol class='carousel-indicators' id='olnum'></ol>");

                var lunbotuTd = $("<div class='carousel-inner' id='lunbotu'></div>");

                var imagList = result.data.prizeDTOList;
                // console.log(imagList);
                $.each(imagList, function (index, item) {
                    if (index == 0) {
                        $("<li class='active' data-target='#carouselExampleIndicators' data-slide-to='" + index + "'></li>").appendTo(olnumTd);
                        $("<div class='carousel-item active'><img alt='...' class='d-block w-100' src=" + item.prizeImagUrl + " /></div>").appendTo(lunbotuTd);
                    } else {
                        $("<li data-target='#carouselExampleIndicators' data-slide-to='" + index + "'></li>").appendTo(olnumTd);
                        $("<div class='carousel-item '><img alt='...' class='d-block w-100' src=" + item.prizeImagUrl + " /></div>").appendTo(lunbotuTd);
                    }
                });
                olnumTd.appendTo(carouseTd);
                lunbotuTd.appendTo(carouseTd);
                carouseTd.appendTo(imagTd);

                var person = $("<p id='person' style='display: inline'>当前已参与人数:"+nums+" </p>");
                var minimumPerson = $("<p style='display: inline'></p>").append("  |  最低参与人数:" + result.data.minimumPerson);
                var h5 = $("<br><br><br><br><h5></h5>").append(person).append(minimumPerson);
                var status = $("<p style='color:red;'>开奖状态:</p>").append(result.data.lotteryStatus == 0 ? '未开奖' : '已开奖');
                var button = $("<button class='btn btn-primary' type='button' id='join' data-toggle='popover' data-placement='bottom'>点击扫码参与</button>");
                var qrCode = $("<div class='col-lg-6 ' style='text-align:center; '></div>").append(h5).append(status).append(button);

                var storeName = $("<li><strong>" + result.data.storeName + "</strong></li>");
                var time = $("<h5 class='float-right mr-0'>" + result.data.startTime + "~" + result.data.dueTime + "</h5>");
                var clearfix = $("<div class='post-meta clearfix'></div>").append($("<ul></ul>").append(storeName).append(time));
                var lotteryTitle = $("<h2>" + result.data.lotteryTitle + "</h2>");
                var lotteryExplain = $("<p style='white-space: pre-wrap'>" + result.data.lotteryExplain + "</p>");
                var detail = $("<div class='detail'></div>").append(clearfix).append(lotteryTitle).append(lotteryExplain);
                $("<div class='col-lg-12 col-md-12'></div>").append($("<div class='blog-2'></div>").append($("<div class='row'></div>").append(imagTd).append(qrCode)).append(detail)).appendTo("#body");
                $("#join").popover({
                    trigger: "foucs",
                    html: true,
                    content: "<img alt='...' src='" + result.data.qrCode + "' height='75%' width='75%'/>"
                });
            }
        });
    }

    function getJoinNums(id) {
        var nums = null;
        $.ajax({
            url: "http://localhost:5761/lottery-system-lottery/lottery/api/lottery/numbers/" + id,
            type: "GET",
            async: false,
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("token", token);
            },
            success: function (result) {
                nums = result;
            }
        });
        return nums;
    }


</script>

</body>
</html>